/**
 * 管理初始化
 */
var UkeyUploadfile = {
    id: "UkeyUploadfileTable",	// 表格id
    seItem: null,		// 选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
UkeyUploadfile.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: $.i18n.prop('uploadFile.Belonger'), field: 'userName', visible: true, align: 'center', valign: 'middle'},
            {title: $.i18n.prop('uploadFile.CertificatePath'), field: 'certificatePath', visible: true, align: 'center', valign: 'middle'},
            {title: "<font color='blue'>"+$.i18n.prop('uploadFile.notBeforeTime')+"</font>", field: 'notBeforeTime', visible: true, align: 'center', valign: 'middle',
            	sortable: true,
            	sortName: "NOT_BEFORE_TIME",
            	formatter:function (value) {
            		if(value != null){
            			return (new Date(value)).Format("dd/MM/yyyy hh:mm:ss");
            		}
                }
            },
            {title: "<font color='blue'>"+$.i18n.prop('uploadFile.notAfterTime')+"</font>", field: 'notAfterTime', visible: true, align: 'center', valign: 'middle',
            	sortable: true,
            	sortName: "NOT_AFTER_TIME",
            	formatter:function (value) {
            		if(value != null){
            			return (new Date(value)).Format("dd/MM/yyyy hh:mm:ss");
            		}
                }
            },
            {title: $.i18n.prop('uploadFile.Remark'), field: 'remarks', visible: true, align: 'center', valign: 'middle'},
            {title: "<font color='blue'>"+$.i18n.prop('uploadFile.createTime')+"</font>", field: 'createDate', visible: true, align: 'center', valign: 'middle',
            	sortable: true,
            	sortName: "CREATE_DATE",
            	formatter:function (value) {
            		return (new Date(value)).Format("dd/MM/yyyy hh:mm:ss");
                }
            }
    ];
};

/**
 * 检查是否选中
 */
UkeyUploadfile.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info($.i18n.prop("common.check"));
        return false;
    }else{
        UkeyUploadfile.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
UkeyUploadfile.openAddUkeyUploadfile = function () {
    var index = layer.open({
        type: 2,
        title: $.i18n.prop("common.add.title"),
        area: ['800px', '420px'], // 宽高
        fix: false, // 不固定
        maxmin: true,
        content: Feng.ctxPath + '/ukeyUploadfile/ukeyUploadfile_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
UkeyUploadfile.openUkeyUploadfileDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: $.i18n.prop("common.edit.title"),
            area: ['800px', '420px'], // 宽高
            fix: false, // 不固定
            maxmin: true,
            content: Feng.ctxPath + '/ukeyUploadfile/ukeyUploadfile_update/' + UkeyUploadfile.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
UkeyUploadfile.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/ukeyUploadfile/delete", function (data) {
            Feng.success($.i18n.prop("common.delete.success"));
            UkeyUploadfile.table.refresh();
        }, function (data) {
            Feng.error($.i18n.prop("common.delete.failed"));
        });
        ajax.set("ukeyUploadfileId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询列表
 */
UkeyUploadfile.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    UkeyUploadfile.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = UkeyUploadfile.initColumn();
    var table = new BSTable(UkeyUploadfile.id, "/ukeyUploadfile/list", defaultColunms);
    table.setPaginationType("server");
    UkeyUploadfile.table = table.init();
});
